package com.syx.system.Manager;

import com.syx.common.redis.Service.RedisService;
import com.syx.commoncore.Constant.CacheConstant;
import com.syx.system.Model.exam.Exam;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExamCacheManager {

    @Resource
    private RedisService redisService;

    public void addCache(Exam exam) {
        //向未完赛列表中添加
        redisService.leftPushForList(getExamListKey(), exam.getExamId());
        //添加另一个key和value
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    public void deleteCache(Long examId) {
        redisService.removeForList(getExamListKey(), examId);
        redisService.deleteObject(getDetailKey(examId));
        redisService.deleteObject(getExamQuestionListKey(examId));
    }

    //返回未完赛列表
    private String getExamListKey() {
        return CacheConstant.EXAM_UNFINISHED_LIST;
    }


    //竞赛详细信息+examId为另外一个的key
    private String getDetailKey(Long examId) {
        return CacheConstant.EXAM_DETAIL + examId;
    }

    private String getExamQuestionListKey(Long examId) {
        return CacheConstant.EXAM_QUESTION_LIST + examId;
    }
}